<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:wh="http://java.sun.com/jsf/composite/wh"
	xmlns:p="http://primefaces.org/ui">
<h:body>
	<ui:composition template="template/template.xhtml">
		<ui:define name="content">
			<h:form id="form" styleClass="horizontal_full">
				<p:panel id="roundSimulationPanel">
					<p:breadCrumb>
						<p:menuitem value="Categories" url="adminGameManagement.xhtml#" />
						<p:menuitem value="#{adminMBean.selectedGame.name}"
							url="adminGameManagement.xhtml#" />
					</p:breadCrumb>
					<h1>Round Management</h1>
					<p>
						Allows you to configure, add and delete different rounds in the game, start the simulation and show the agenttypes that are used in this round for the agent creation.
						The AgentType of a simulated round and their created agents will be automatically added in the next round. So if you don't need them please just delete the agenttype after the simulation 
						of the next round.
					</p>
					<p:dataTable id="roundTable" var="round"
						value="#{adminMBean.selectedGame.rounds}" selectionMode="single"
						rowKey="#{round.roundNumber}"
						paginatorTemplate="{RowsPerPageDropdown} {CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"
						rowsPerPageTemplate="10,25,50,100" paginator="true" rows="100">

						<f:facet name="header">
					            Round Overview for Game: #{adminMBean.selectedGame.name}
					        </f:facet>

						<p:column headerText="Roundnumber" sortBy="#{round.roundNumber}">
							<h:outputText value="#{round.roundNumber}" />
						</p:column>

						<p:column headerText="Startdate" sortBy="#{round.startDate}">
							<h:outputText value="#{round.startDate}">
								 <f:convertDateTime pattern="dd.MM.yyyy HH:mm" />
							</h:outputText>
						</p:column>

						<p:column headerText="Enddate" sortBy="#{round.endDate}">
							<h:outputText value="#{round.endDate}">
								<f:convertDateTime pattern="dd.MM.yyyy HH:mm" />
							</h:outputText>
						</p:column>

						<p:column headerText="Played" sortBy="#{round.played}">
							<p:outputPanel layout="inline" styleClass="ui-icon ui-icon-circle-check" rendered="#{round.played}" />
							<p:outputPanel layout="inline" styleClass="ui-icon ui-icon-circle-close" rendered="#{!round.played}" />
						</p:column>

						<p:ajax event="rowSelect"
							listener="#{adminMBean.eventRoundRowSelect}" update=":messages" />

						<p:column headerText="Show Agenttypes">
							<p:commandButton icon="ui-icon-search" title="View"
								action="#{adminMBean.actionShowAgentTypes()}">
								<f:setPropertyActionListener value="#{round}"
									target="#{adminMBean.selectedRound}" />
							</p:commandButton>
						</p:column>
						
						<p:column headerText="Configure Round">
							<p:commandButton icon="ui-icon-gear" title="Configure" update=":form"
								action="#{adminMBean.actionGoToUpdateRound()}"
								disabled="#{round.played}" >
								<f:setPropertyActionListener value="#{round}"
									target="#{adminMBean.selectedRound}" />
							</p:commandButton>
						</p:column>
						
						<p:column headerText="Delete Round">
							<p:commandButton icon="ui-icon-circle-minus" title="Delete"
								action="#{adminMBean.actionDeleteRound()}" disabled="#{round.played}" update=":form">
								<f:setPropertyActionListener value="#{round}" target="#{adminMBean.selectedRound}" />
							</p:commandButton>
						</p:column>
						
						
						<p:column headerText="Do Simulation">
								<p:commandButton id="cmdSimulation" icon="ui-icon-triangle-1-e" title="Simulation"
									action="#{adminMBean.actionStartSimulation()}"
									disabled="#{not round.allowSimulationForRound()}"
									update="roundTable">
									<f:setPropertyActionListener value="#{round}"
										target="#{adminMBean.selectedRound}" />
									<p:confirm header="Confirmation"
										message="Are you sure to start the simulation?"
										icon="ui-icon-alert" />
								</p:commandButton>
								<p:blockUI block="roundTable" trigger="cmdSimulation">
									SIMULATION<br></br>
									<p:graphicImage library="img" name="ajaxloadingbar.png"/>
								</p:blockUI>
								<p:confirmDialog global="true" showEffect="fade"
									hideEffect="explode">
									<p:commandButton value="Yes" type="button"
										styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
									<p:commandButton value="No" type="button"
										styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
								</p:confirmDialog>
						</p:column>

						<f:facet name="footer">
						    	<p:commandButton value="Create New Round"
									action="#{adminMBean.actionGoToCreateRound()}"
									update=":form" icon="ui-icon-circle-plus"/>
					    </f:facet>
					</p:dataTable>

				</p:panel>
			</h:form>
		</ui:define>
	</ui:composition>
</h:body>
</html>